import { getPageSheetNode } from '@/utils/helpers'

export default function (editor) {
  const checkPageLayout = (layout) => (getPageSheetNode(editor)?.dataset?.layout || 'portrait') === layout
  const setPageLayout = (layout) => (getPageSheetNode(editor).dataset.layout) = layout

  // 右键 - 纵向
  editor.ui.registry.addToggleMenuItem('contextmenu_layout_portrait', {
    text: '页面纵向',
    onSetup: function (api) {
      api.setActive(checkPageLayout('portrait'))
      return function () { }
    },
    onAction() {
      setPageLayout('portrait')
      editor.undoManager.add()
    }
  })

  // 右键 - 横向
  editor.ui.registry.addToggleMenuItem('contextmenu_layout_landscape', {
    text: '页面横向',
    onSetup: function (api) {
      api.setActive(checkPageLayout('landscape'))
      return function () { }
    },
    onAction() {
      setPageLayout('landscape')
      editor.undoManager.add()
    }
  })

  // console.debug('---右键菜单: 布局---')
}
